package priv.wjh.study.cloud.feign.api.impl;

import org.junit.jupiter.api.Assertions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import priv.wjh.study.cloud.feign.ArgsException;
import priv.wjh.study.cloud.feign.api.MyTestVo;
import priv.wjh.study.cloud.feign.api.StudyFeignApi;
import priv.wjh.study.cloud.feign.api.ao.BaseAo;
import priv.wjh.study.cloud.feign.api.ao.TestOneAo;
import priv.wjh.study.cloud.feign.api.ao.TestTweAo;

/**
 * //TODO
 *
 * @author wangjunhao
 **/
@RequestMapping("/test")
@RestController
public class StudyFeignApiImpl implements StudyFeignApi {

    @Override
    public String test() {
        return "Really implement";
    }


    @Override
    public MyTestVo test2() {
        MyTestVo myTestVo = new MyTestVo();
        myTestVo.setTest1("test11111");
        myTestVo.setTest2(12222);
        return myTestVo;
    }


    @Override
    public <T extends BaseAo> void genericTest(T ao) {
        if (ao instanceof TestOneAo) {
            TestOneAo testOneAo = (TestOneAo) ao;
            Assertions.assertEquals(testOneAo.getVal(), "TestOneAo");
            return;
        }
        if (ao instanceof TestTweAo) {
            TestTweAo testTweAo = (TestTweAo) ao;
            Assertions.assertEquals(testTweAo.getVal(), "TestTweAo");
            return;
        }
        throw new ArgsException();
    }

    @Override
    public BaseAo getAo(Integer type) {
        if (type == 1) {
            return new TestOneAo();
        }
        if (type == 2) {
            return new TestTweAo();
        }
        return new BaseAo();
    }
}
